package service

import (
	"api-gateway/basic/config"
	__ "api-gateway/basic/proto/rpc"
	"api-gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddComment(c *gin.Context) {
	var form request.AddComment
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
		return
	}
	comment, err := config.VideoRpcClient.AddComment(c, &__.AddCommentReq{
		UserId:  form.UserId,
		VideoId: form.VideoId,
		Content: form.Content,
		Pid:     form.Pid,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "发送弹幕完成", "data": gin.H{
		"comment": comment.CommentId,
	}})
	return
}

func GetCommentList(c *gin.Context) {
	var form request.GetCommentList
	if err := c.ShouldBind(&form); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": "参数错误"})
		return
	}
	comment, err := config.VideoRpcClient.GetCommentList(c, &__.GetCommentListReq{
		VideoId: form.VideoId,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": 400, "msg": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "msg": "发送弹幕完成", "data": gin.H{
		"list": comment.List,
	}})
	return
}
